﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ArasPLMExtend
{
    public partial class FrmBOMFromERP : Form
    {
        public FrmBOMFromERP()
        {
            InitializeComponent();
        }

        private void FrmBOMFromERP_Load(object sender, EventArgs e)
        {
            Dictionary<string, string> compList = ERPConnection.CERPFunction.getCompDataNamesAndCpno();
            cbxCompList.DataSource = new BindingSource(compList, null);
            cbxCompList.DisplayMember = "Value";
            cbxCompList.ValueMember = "Key";
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void txtPrdNo_Leave(object sender, EventArgs e)
        {
            if (!ERPConnection.CERPFunction.checkPrdNo(txtPrdNo.Text.ToUpper().Trim(), cbxCompList.SelectedValue.ToString()))
            {
                MessageBox.Show("输入的货品在对应帐套中不存在，请核查！");
            }
        }

        private void btnImport_Click(object sender, EventArgs e)
        {
            if (!ERPConnection.CERPFunction.checkPrdNo(txtPrdNo.Text.ToUpper().Trim(), cbxCompList.SelectedValue.ToString()))
            {
                MessageBox.Show("输入的货品在对应帐套中不存在，请核查！");
            }
            else
            {
                this.Hide();
                FrmImportProcess myprocess = new FrmImportProcess(txtPrdNo.Text.ToUpper().Trim(),cbxCompList.SelectedValue.ToString());
                if(myprocess.ShowDialog()==DialogResult.OK)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
        }
    }
}
